# @Filename:    Sample1-add
# @Author:      王佳伟
# @Time:        2025-02-28 9:25
# @Describe:    统计字符串中的字符出现次数
import unittest


def count_chars(s):
    char_count = {}
    for char in s:
        if char in char_count:
            char_count[char] += 1
        else:
            char_count[char] = 1
    return char_count


class TestCountChars(unittest.TestCase):
    def test_count_chars(self):
        self.assertEqual(count_chars("hello"), {'h': 1, 'e': 1, 'l': 2, 'o': 1})
        self.assertEqual(count_chars(""), {})


if __name__ == '__main__':
    unittest.main()
